//
//  KOFYvideo.m
//  Video Player
//
//  Created by Warren Holybee on 11/16/10.
//  Copyright 2010 Warren Holybee. All rights reserved.
//

#import "KOFYvideo.h"


@implementation KOFYvideo
@synthesize URLString;
@synthesize title;
@synthesize view;

-(void) playVideo 
{
	
	NSLog(@"URLString = %@",URLString);
	// create URL object
	NSURL *myURL = [[NSURL alloc] initWithString:URLString ];
	
	
	//create Movie Object
	MPMoviePlayerController *movie = [[MPMoviePlayerController alloc] initWithContentURL:myURL];

[[NSNotificationCenter defaultCenter] addObserver:self  
                                          selector:@selector(moviePlayBackDidFinish:)  
                                              name:MPMoviePlayerPlaybackDidFinishNotification  
                                            object:movie];  
	
	
	
if ([movie respondsToSelector:@selector(setFullscreen:animated:)]) {  
   // Use the new 3.2 style API  
	NSLog(@"3.2 API");
	
	[[NSNotificationCenter defaultCenter] addObserver:self  
											 selector:@selector(moviePlayBackDidFinish:)  
												 name:MPMoviePlayerDidExitFullscreenNotification  
											   object:movie];  
	
	
   movie.controlStyle = MPMovieControlStyleFullscreen;  
   movie.shouldAutoplay = YES;  
   [self.view addSubview:movie.view];  
   [movie setFullscreen:YES animated:YES];  
	
		
 } else {  
	 NSLog(@"2.0 API");
   // Use the old 2.0 style API  
 //  movie.movieControlMode = MPMovieControlModeHidden;  

	 [movie play];  
 }  
	

}
	- (void) moviePlayBackDidFinish:(NSNotification*)notification {
		MPMoviePlayerController *movie = [notification object];
		[[NSNotificationCenter defaultCenter] removeObserver:self
														name:MPMoviePlayerPlaybackDidFinishNotification
													  object:movie];
		
		// If the moviePlayer.view was added to the view, it needs to be removed
		if ([movie respondsToSelector:@selector(setFullscreen:animated:)]) {
			[movie.view removeFromSuperview];
		}
		[movie stop];
		[movie release];
	}
	




@end
